﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using AgileZen.Models;

namespace AgileZen.Sample.Controllers
{
    public class ProjectController : AgileZenController
    {
        public ActionResult Index()
        {
            var projects = AgileZenService.GetProjects();

            return View(projects);
        }

        public ActionResult Details(int id)
        {
            var project = AgileZenService.GetProject(id, "details");

            return View(project);
        }

        public ActionResult Phases(int id)
        {
            var project = AgileZenService.GetProject(id, "phases");

            return View(project);
        }
        
        public ActionResult Members(int id)
        {
            var project = AgileZenService.GetProject(id, "members");

            return View(project);
        }

        public ActionResult Roles(int id)
        {
            var project = AgileZenService.GetProject(id, "roles");

            return View(project);
        }

        public ActionResult Invites(int id)
        {
            var project = AgileZenService.GetProject(id, "invites");

            return View(project);
        }

        public ActionResult Metrics(int id)
        {
            var project = AgileZenService.GetProject(id, "metrics");

            return View(project);
        }

        public ActionResult Full(int id)
        {
            var project = AgileZenService.GetProject(id, "phases");

            return View(project);
        }

        public ActionResult ProjectMembers(int projectid)
        {
            var project = AgileZenService.GetProjectMembers(projectid);

            return View(project);
        }


        //
        // POST: /Project/Edit/5

        public ActionResult Edit(int projectid)
        {

            try
            {
                var project = AgileZenService.GetProject(projectid, "details");
                return View(project);
            }
            catch
            {
                return View();
            }

        }

        [HttpPost]
        public ActionResult Edit(int id, Project project)
        {
            try
            {
                AgileZenService.UpdateProject(id, ref project);
                // TODO: Add update logic here
                return RedirectToAction("Index");
            }
            catch
            {
                return View(project);
            }
        }

        
    }
}
